﻿@page "/"
@using BlaMauiApp.Data
@inject LoginUserManager loginUserManager

<h1>Hello, world!</h1>

Welcome to your new app.

<SurveyPrompt Title="How is Blazor working for you?" />

@if (isAuthenticated)
{
    <p>您已经登录</p>

    <div class="card">
        <div class="card-header">
            <h2>用户信息</h2>
        </div>
        <div class="card-body">
            <dl>
                <dt>AccessToken</dt>
                <dd>@userInfo.AccessToken</dd>
                <dt>RefreshToken</dt>
                <dd>@userInfo.RefreshToken</dd>
                <dt>ExpiresIn</dt>
                <dd>@userInfo.ExpiresIn</dd>
                <dt>UserId</dt>
                <dd>@userInfo.UserId</dd>
                <dt>Username</dt>
                <dd>@userInfo.Username</dd>
                <dt>UserRole</dt>
                <dd>@userInfo.UserRole</dd>
            </dl>
        </div>
    </div>

    <button class="nav-link" @onclick="Logout">退出登录</button>
}
else
{
    <p>您还没有登录，请先登录</p>
    <a class="nav-link" href="phonecodelogin">登录</a>
}

@code {
    private bool isAuthenticated => loginUserManager.IsAuthenticated;
    private LoginUserInfo userInfo => loginUserManager.UserInfo;

    private void Logout()
    {
        loginUserManager.Logout();

        StateHasChanged();
    }

}